home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Information / WebSites / Wirenet / arexx / CleanSystem.lha / Thor / Rexx / CleanSystem.thor
Text File  |  1998-09-11  |  2KB  |  80 lines

  1. /*
  2. $VER: CleanSystem.thor 0.3 (12.1.98)
  3. © Neil Bothwick
  4. */
  5.  
  6. /* Removes "orphaned" files from the system directory,              */
  7. /* left over from previously deleted conferences                    */
  8. /* Copy this script to Thor/rexx and run it from Thor's arexx menu. */
  9. /* It will clean orphaned files from the current system             */
  10.  
  11. /*;;; Initialise */
  12. options results
  13. FoundCount = 0
  14. DelCount = 0
  15. ;;;
  16. /* ;;;Needs THOR and bbsread.library functions */
  17. thorport = address()
  18. if left(thorport,5) ~= 'THOR.' then do
  19.     say 'CleanSystem.thor must be run from within Thor.'
  20.     exit
  21.     end
  22.  
  23. if ~show('p', 'BBSREAD') then do
  24.     address command
  25.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  26.     'WaitForPort BBSREAD'
  27.     end
  28. ;;;
  29. /* ;;;Get current system name,conference list and data directory */
  30. address(thorport)
  31. drop TMP.
  32. 'CURRENTSYSTEM stem TMP'
  33. System = TMP.BBSNAME
  34. address 'BBSREAD'
  35. drop TMP. CONFLIST.
  36. 'GETCONFLIST "'System'" CONFLIST'
  37. 'GETBBSDATA "'system'" stem TMP'
  38. SystemDir = TMP.BBSPATH
  39. call pragma('D',SystemDir)
  40. ;;;
  41. /* ;;; Build file list and compare each entry with the conference list */
  42. address command 'list' SystemDir 'pat MsgData#? files lformat "%N %C" to T:CleanSystem.tmp'
  43. if ~open(FileList,'T:CleanSystem.tmp','R') then call ExitMsg('Failed to open temporary file')
  44. address(thorport)
  45. do until eof(FileList)
  46.     line = readln(FileList)
  47.     if line = '' then iterate
  48.     File = subword(line,1,1)
  49.     FileNo = substr(File,8)
  50.     Conf = subword(line,2)
  51.     if Conf = '' then call ExitMsg('File found with no comment')
  52.     do i = 1 to CONFLIST.COUNT
  53.         if upper(CONFLIST.i) == upper(Conf) then leave
  54.         end
  55.     if i > CONFLIST.COUNT then do
  56.         FoundCount = FoundCount + 1
  57.         'REQUESTNOTIFY TEXT "File 'File' matches non-existent conference:\n'Conf'" BT "Delete|Leave"'
  58.         if result = 1 then do
  59.             DelCount = DelCount + 1
  60.             address command 'delete >NIL:' File 'MsgHash'FileNo 'MsgHead'FileNo 'MsgMarked'FileNo 'MsgText'FileNo
  61.             end
  62.         end
  63.     end
  64. call close(FileList)
  65. address command 'Delete >NIL: T:CleanSystem.tmp'
  66. If FoundCount = 0 then ReportText = 'No orphaned files found'
  67. else ReportText = 'Found orphaned files for' FoundCount 'deleted conferences\nDeleted 'DelCount
  68. 'REQUESTNOTIFY TEXT "'ReportText'" BT "OK"'
  69. if RC > 0 then call ExitMsg(THOR.LASTERROR)
  70. ;;;
  71. exit
  72.  
  73. /* ;;; Exit with a message */
  74. ExitMsg:
  75.     parse arg ErrTxt
  76.     address(thorport)
  77.     'REQUESTNOTIFY "'ErrTxt'" "Abort"'
  78.     exit
  79. ;;;
  80.